Source for file persistence.php
Documentation is available at persistence.php
* This file groups classes pertaining to data persistence.
* @author Antoine d'Otreppe de Bouvette <a.dotreppe@aspyct.org>
* @license http://www.opensource.org/licenses/mit-license.php
* @todo Make usage of "query" and "statement" more clear.
* @todo Write a DAO that maps to entities.
* Offers connectivity to databases.
* Refer to {@link http://www.php.net/manual/pdo.construct.php PDO} for
* details about this constructor.
* @param string $username
* @param array $driver_options
public function __construct($dsn, $username= Null, $passwd= Null,
$driver_options= array()) {
parent::__construct($dsn, $username, $passwd, $driver_options);
$this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
* Serves as a basis for a PDO DAO.
* Prepares and executes a SQL $statement within the connection
* @param string $statement
protected function execute($statement, $args= array()) {
$ps = $this->ds->prepare($statement);
* Executes an insert statement and returns the last insert id.
* @todo Make it more transparent for PostgreSQL: it might guess serial name
* @param string $statement
* @return int the last insert id for the data source
return $this->ds->lastInsertId($serial);
* Executes a statement and maps the resulting rows with
* {@link AbstractDAO::hydrate()}.
* @param string $statement
protected function select($statement, $args= array()) {
$statement = $this->execute($statement, $args);
$cb = array($this, 'hydrate');
return array_map($cb, $statement->fetchAll(PDO::FETCH_ASSOC));
* This default implementation returns the row itself.
* Override this method to add custom behaviour.
* @param array $row an associative array containing row values.
* Exception thrown when there is no more row to build
|